<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
<head>
<script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="js/plugin/jquery-jtemplates.js" type="text/javascript"></script>
<script src="js/plugin/jquery-ui-1.8.12.custom.min.js"
	type="text/javascript"></script>
<script src="js/plugin/jquery.bgiframe-2.1.2.js" type="text/javascript"></script>
<script src="js/plugin/jquery.validate.min.js" type="text/javascript"></script>
<script src="js/plugin/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="js/hnl-common.js" type="text/javascript"></script>
<script src="js/hnl-search.js" type="text/javascript"></script>
<script src="js/hnl-dialogObj.js" type="text/javascript"></script>
<script src="js/hnl-authorize.js" type="text/javascript"></script>
<link href="css/jquery/jquery.ui.all.css" rel="stylesheet"></link>
<link href="css/jquery/jquery.ui.dialog.css" rel="stylesheet"></link>
<link href="css/search.css" rel="stylesheet"></link>
<link href="css/hnl-main.css" rel="stylesheet"></link>
<link href="css/hnl-table.css" rel="stylesheet"></link>
<script>
	$(document).ready(
			function() {
				/* Set page style */
				$("#main").addClass("ui-widget");

				/* Set authorization MUST USE SINGLE QUOTES AS JAVA RETURNS DOUBLE QUOTES*/
				var authorizeAccess = getFromAttribute('${roleFunctionsMap}');
				var authorizeObj = new HnlAuthorizeObj(authorizeAccess);
				authorizeObj.authorizePageFunctions();

				var deleteTalentDialog1 = new HnlDialogObj("#dialog-confirm",
						"#delTalentButton1", "/hnl/DeleteTalent.do");
				deleteTalentDialog1.buildDialog();
				deleteTalentDialog1.addDialogFunctions();
				
				var deleteTalentDialog2 = new HnlDialogObj("#dialog-confirm",
						"#delTalentButton2", "/hnl/DeleteTalent.do");
				deleteTalentDialog2.buildDialog();
				deleteTalentDialog2.addDialogFunctions();

				/*Draw table*/
				loadTemplate("#personalList",
						"/hnl/template/talentTableTemplate.jsp",
						"#personalListTemplate", "checkboxAll");
				loadTemplate("#allList",
						"/hnl/template/talentTableTemplate2.jsp",
						"#allListTemplate", "checkboxAll");
				loadTableData("#personalList", "#personalListTemplate",
						"/hnl/LoadAllTalent.do");
				loadTableData("#allList", "#allListTemplate",
						"/hnl/LoadAllTalent.do");

				/*Button action*/

				$("#addTalent1").click(function() {
					//window.location.replace("talentInfo.jsp");
					window.location.href = "talentInfo.jsp";
				});

				$("#addTalent2").click(function() {
					window.location.replace("talentInfo.jsp");
				});

				/* Initialize search */
				$("#backToMain").hide();
				$("#backToMain").click(function(evt) {
					evt.preventDefault();
					window.top.location.href = "dashboard.jsp";
				});

				$("#advancedSearch").hide();

				$("#search").click(function() {
					$("#backToMain").show();
					var strURL = "/solr/select";
					var params = getStandardArgs().concat(getQueryString());
					var strData = strURL + "?" + params.join('&');

					$.getJSON(strData, function(data) {
						updateSearchResult(data);
					});
				});

				$("#searchMode").click(function(evt) {
					if ($("#basicSearch").is(":visible")) {
						$("#advancedSearch").show();
						$("#basicSearch").hide();
						$("#searchMode").attr("value", "Basic Search");
					} else {
						$("#advancedSearch").hide();
						$("#basicSearch").show();
						$("#searchMode").attr("value", "Advanced Search");
					}
				});

				$("#logout").click(function() {
					$("#main").attr("action", "/hnl/UserLogout.do");
					$("#main").attr("method", "post");
					$("#main").submit();
				});

			});

	function updateSearchResult(sjson) {
		// Set URL of the template. Setting filter_data to false - prevents HTML encode 
		$("#talentMgmtFieldset").setTemplateURL(
				"/hnl/template/talentSearchTableTemplate.jsp", [], {
					filter_data : false
				});
		// Function call to create function within the template and assign value (function object)
		$("#talentMgmtFieldset").setParam("checkHighlighting",
				checkHighlighting);
		$("#talentMgmtFieldset").processTemplate(sjson);

		$("tr[name='searchResultrow']").each(function() {
			$(this).click(function(evt) {
				window.open("talentInfo.jsp?talentID=" + $(this).attr("id"));
			});
		});
		$("#searchListBody tr:odd").addClass("searchResult_firstRow");
		$("#searchListBody tr:even").addClass("searchResult_secondRow");
	}
</script>

</head>
<body class="formBody">
	<form id="main">
		<div class="welcomeInfo">
			<table>
				<tr>
					<td>Welcome</td>
					<td class="message1"><c:out value="${loggedInUser.firstname}" />
						<c:out value="${loggedInUser.lastname}" />
					</td>
					<td>(</td>
					<td class="message1"><c:out value="${loggedInUser.email}" />
					</td>
					<td>)</td>
					<td style="display: none" class="UserManagementAccess">| <a
						href="/hnl/userDashboard.jsp">Consultant Management</a>
					</td>
					<td>| <input class="button_short" id="logout" type="button"
						value="Logout" /></td>
				</tr>
			</table>
		</div>
		<div style="clear: both;"></div>
		<fieldset class="mainFieldSet searchInput">
			<legend class="mainLegend">&nbsp;Search for Talent&nbsp;</legend>
			<div id="basicSearch" class="textBlock ">
				<table class="twoColumn">
					<tr>
						<td class="firstCol"><label for="search">Search
								Keyword</label>
						</td>
						<td class="secondCol"><input id="keyword" name="keyword"
							type="text" /></td>
					</tr>
				</table>
				<!-- 
				<label for="search" >Search Keyword</label> <input id="keyword"
					name="keyword" type="text" size="100" />
				 -->
			</div>
			<div id="advancedSearch">
				<label for="advSearch">Find Talent that has...</label><br />
				<table class="twoColumn">
					<tr>
						<td class="firstCol">all these words:</td>
						<td class="secondCol"><input id="allTheseWords"
							name="allTheseWords" type="text" value="" /></td>
					</tr>
					<tr>
						<td>exact phrase:</td>
						<td><input id="exactPhrase" name="exactPhrase" type="text"
							value="" /></td>
					</tr>
					<tr>
						<td>one or more:</td>
						<td><input id="oneOrMore" name="oneOrMore" type="text"
							value="" /></td>
					</tr>
					<tr>
						<td>unwanted words:</td>
						<td><input id="unWantedWords" name="unWantedWords"
							type="text" value="" /></td>
					</tr>
					<tr>
						<td>build your own query:</td>
						<td><input id="buildYourOwnQuery" name="buildYourOwnQuery"
							type="text" value="" /></td>
					</tr>
				</table>
			</div>
			<input class="button_short" id="search" type="button" value="Search" />
			<input class="button_long" id="searchMode" type="button"
				value="Advanced Search" /> <input class="button_long" type="button"
				id="backToMain" value="Back to Main" />
		</fieldset>
		<fieldset id="talentMgmtFieldset" class="mainFieldSet">
			<legend class="mainLegend">Talent Management</legend>
			<fieldset class="subFieldSet">
				<div>
					<img class="actionIcon" id="addTalent1" class="add"
						src="./images/add.png"></img>&nbsp;&nbsp; <img
						style="display: none"
						class="delTalent actionIcon DeleteTalentAccess"
						id="delTalentButton1" src="./images/del.png"></img>
				</div>
				<legend class="subLegend">
					<c:out value="${loggedInUser.firstname}" />
					<c:out value="${loggedInUser.lastname}" />
					's List
				</legend>
				<div id="personalList"></div>
			</fieldset>
			<fieldset class="subFieldSet">
				<legend class="subLegend">All Profiles</legend>
				<div>
					<img class="actionIcon" id="addTalent2" class="add"
						src="./images/add.png"></img>&nbsp;&nbsp; <img
						style="display: none"
						class="delTalent actionIcon DeleteTalentAccess"
						id="delTalentButton2" src="./images/del.png"></img>
				</div>
				<div id="allList"></div>
			</fieldset>
		</fieldset>
	</form>
	<div id="dialog-confirm" title="Delete Talents">
		<p>
			<span class="ui-icon ui-icon-alert"
				style="float: left; margin: 0 7px 20px 0;"></span>Do you really want
			to delete Talent(s) from the database?
		</p>
	</div>
</body>
</html>
